﻿'
' DKP for DotNetNuke® - http://dkpdnn.codeplex.com
' Copyright (c) 2008
' by Casey Lengacher ( http://dkpdnn.codeplex.com )
'
' DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.
'

Namespace DotNetNuke.Modules.tss_DKP

    Partial Public Class tss_ucTools

        Inherits Entities.Modules.PortalModuleBase

#Region "Private Methods"

        Private Sub BindPage()

            Dim tss_DKP As New tss_DataController

            dlPlayers.DataSource = tss_DKP.tss_GetPlayers(CInt(Settings("BoardID")))
            dlPlayers.DataBind()

        End Sub

#End Region

#Region "Private Event Handlers"

        Private Sub ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles dlPlayers.ItemDataBound

            Dim currentPlayer As tss_PlayerInfo
            Dim lblPlayerID As Label

            If (e.Item.ItemType.Equals(ListItemType.Item)) Or (e.Item.ItemType.Equals(ListItemType.AlternatingItem)) Then

                lblPlayerID = e.Item.FindControl("lblPlayerID")

                currentPlayer = e.Item.DataItem

                lblPlayerID.Text = currentPlayer.PlayerID.ToString()

            End If

        End Sub

        Private Sub Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkRandomCalculatorSubmit.Click

            Dim tss_DKP As New tss_DataController
            Dim objPlayer As tss_PlayerInfo
            Dim currentPlayer As DataListItem
            Dim chkPlayer As CheckBox
            Dim lblPlayerID As Label
            Dim intRandom As Integer = 1
            Dim txtOutput As String = ""

            If (sender.Equals(lnkRandomCalculatorSubmit)) Then

                For Each currentPlayer In dlPlayers.Items

                    If (currentPlayer.ItemType.Equals(ListItemType.Item)) Or (currentPlayer.ItemType.Equals(ListItemType.AlternatingItem)) Then

                        chkPlayer = currentPlayer.FindControl("chkPlayer")
                        lblPlayerID = currentPlayer.FindControl("lblPlayerID")

                        If (sender.Equals(lnkRandomCalculatorSubmit)) Then

                            If (chkPlayer.Checked) Then

                                objPlayer = tss_DKP.tss_GetPlayer(CInt(lblPlayerID.Text))

                                If (objPlayer.SavedDKP > 0) Then

                                    If (txtOutput.Length = 0) Then
                                        txtOutput = objPlayer.PlayerName + " (1-" + objPlayer.SavedDKP.ToString() + ")"
                                        intRandom = objPlayer.SavedDKP + 1
                                    Else
                                        txtOutput = txtOutput + ", " + objPlayer.PlayerName + " (" + intRandom.ToString() _
                                            + "-" + (intRandom + objPlayer.SavedDKP - 1).ToString() + ")"
                                        intRandom = intRandom + objPlayer.SavedDKP
                                    End If

                                End If

                            End If

                        End If

                    End If

                Next

                lblRandomCalculatorOutput.Text = "Output: " + txtOutput

            End If

        End Sub

#End Region

#Region "Public Methods"

        Public Sub Initialize()

            BindPage()

            pnlRandomCalculator.Visible = True

            lblRandomCalculatorOutput.Text = "Output: "

        End Sub

#End Region

    End Class

End Namespace
